{extend name="layout/base" /}
<!-- 标题 -->
{block name="title"}添加内容 - {$column['column_name']}{/block}
<!-- CSS -->
{block name="css"}{/block}
<!-- 具体内容 -->
{block name="content"}
<h2 class="header-dividing">添加内容 <small>{$column['column_name']}</small></h2>
<div class="navbar navbar-default navbar-content">
    <div class="collapse navbar-collapse">
        <ul class="nav navbar-nav">
            <li><a href="javascript:history.back();"> <i class="icon icon-double-angle-left"></i> 返回上页</a></li>
            {if($column['column_cate'])}
            <li><a href="{:url('@admin/wscate', $urlparam)}"> <i class="icon icon-branch"></i> 内容分类</a></li>
            {/if}
            <li><a href="{:url('@admin/wscolumn', $urlparam)}"> <i class="icon icon-lightbulb"></i> 栏目设置</a></li>
        </ul>
        <!-- 导航中的表单 -->
        <form class="navbar-form navbar-left" role="search" method="get" action="{:url('@admin/wsarticle')}">
            <input type="hidden" name="siteid" value="{$siteid}">
            <input type="hidden" name="columnid" value="{$columnid}">
            {if($column['column_cate'])}
            <select class="form-control" name="cateid">
                <option value="">请选择分类</option>
                {volist name="wscate" id="vo"}
                <option value="{$vo['wscate_id']}">{:dp_prefix($vo['wscate_path'])} {$vo['wscate_name']}</option>
                {/volist}
            </select>
            {/if}
            <input type="text" class="form-control" name="keywords" placeholder="搜索" value="">
            <button type="submit" class="btn btn-default">搜索</button>
        </form>
    </div>
</div>
<div class="mb10">
    <ul class="nav nav-primary">
        <li class="active"><a data-tab href="#Content1">文章内容</a></li>
        {if($column['column_field'])}<li><a data-tab href="#Content3">扩展内容</a></li>{/if}
        <li><a data-tab href="#Content2">其它内容</a></li>
    </ul>
</div>
<form class="form-horizontal" id="form-page-submit" method="post" action="{:url('@admin/wsarticle/save')}">
    <input type="hidden" name="backurl" value="{:url('@admin/wsarticle','siteid='.$siteid.'&columnid='.$columnid)}">
    <input type="hidden" name="wsarticle_siteid" value="{$siteid}">
    <input type="hidden" name="wsarticle_columnid" value="{$columnid}">
    <div class="panel">
        <div class="panel-body tab-content">
            <fieldset class="tab-pane active" id="Content1">
                <legend>文章内容</legend>
                <div class="form-group">
                    <label class="col-md-2 col-sm-2 required" for="wsarticle_title">标题</label>
                    <div class="col-sm-6 "><input type="text" class="form-control" placeholder="文章标题" name="wsarticle_title" value="" required></div>
                    <div class="col-sm-4 help-block with-errors">Title 页面标题</div>
                </div>
                {if($column['column_cate'] > 0)}
                <div class="form-group">
                    <label class="col-md-2 col-sm-2 required" for="wsarticle_cateid">分类</label>
                    <div class="col-sm-3 ">
                        <select class="form-control" name="wsarticle_cateid[]" required>
                            {volist name="wscate" id="vo"}
                            <option value="{$vo['wscate_id']}">{:dp_prefix($vo['wscate_path'])} {$vo['wscate_name']}</option>
                            {/volist}
                        </select>
                    </div>
                    {if($column['column_cate']==2)}
                    <div class="col-sm-2"><button type="button" class="btn btn-primary" id="btn_add_cate"><i class="icon icon-plus"></i> 添加分类</button></div>
                    {/if}
                    <div class="col-sm-4 help-block with-errors"></div>
                </div>
                <div id="expand_cate_list"></div>
                {/if}
                <div class="form-group">
                    <label class="col-md-2 col-sm-2" for="wsarticle_desc">简介</label>
                    <div class="col-sm-6"><textarea class="form-control" name="wsarticle_desc" rows="3" placeholder="简介"></textarea></div>
                    <div class="col-sm-4 help-block with-errors"></div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 col-sm-2" for="wsarticle_attr">内容</label>
                    <div class="col-sm-10">
                        <script id="wsarticle_details" name="wsarticle_details" type="text/plain"></script>
                    </div>
                </div>
            </fieldset>
            {if($column['column_field'])}
            <fieldset class="tab-pane" id="Content3">
                <legend>扩展内容</legend>
                {volist name="param" id="vo"}
                <div class="form-group">
                    <label class="col-md-2 col-sm-2 {$vo['param_required'] != '1' ?: 'required'}" for="param_{$vo['param_id']}">{$vo['param_name']}</label>
                    {if($vo['param_type']=='editor')}
                        <div class="col-sm-8">{:make_input($vo)}</div>
                        <div class="col-sm-2 help-block">
                            <code>$param_{$vo['param_id']}</code>
                            <p>{$vo['param_tips']}</p>
                        </div>
                    {else /}
                        <div class="col-sm-6">{:make_input($vo)}</div>
                        <div class="col-sm-2 help-block with-errors">&nbsp;{$vo['param_tips']}</div>
                        <div class="col-sm-2 help-block"><code>$param_{$vo['param_id']}</code></div>
                    {/if}
                </div>
                {/volist}
            </fieldset>
            {/if}
            <fieldset class="tab-pane" id="Content2">
                <legend>内容图片</legend>
                <div class="form-group">
                    <label class="col-md-2 col-sm-2" for="wsarticle_image">图片</label>
                    <div class="col-sm-9">
                        <div class="panel mb0" id="upload-list">
                            <div class="panel-body"></div>
                            <div class="panel-footer">
                                <a class="btn btn-upload-file"> <i class="icon icon-picture"></i> 选择图片</a>
                            </div>
                        </div>
                    </div>
                </div>
                <legend>SEO优化</legend>
                <div class="form-group">
                    <label class="col-md-2 col-sm-2" for="wsarticle_page">页面URL</label>
                    <div class="col-sm-6"><input type="text" class="form-control" placeholder="页面URL" name="wsarticle_page"></div>
                    <div class="col-sm-4 help-block with-errors">页面Url，字母，数字，_，-</div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 col-sm-2" for="wsarticle_keywords">页面关键词</label>
                    <div class="col-sm-6"><input type="text" class="form-control" placeholder="页面关键词" name="wsarticle_keywords"></div>
                    <div class="col-sm-4 help-block with-errors">Keywords 页面优化</div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 col-sm-2" for="wsarticle_description">页面描述</label>
                    <div class="col-sm-6"><textarea class="form-control" name="wsarticle_description" placeholder="页面描述"></textarea></div>
                    <div class="col-sm-4 help-block with-errors">Description 页面优化</div>
                </div>
                <legend>其它内容</legend>
                <div class="form-group">
                    <label class="col-md-2 col-sm-2" for="wsarticle_attr">属性</label>
                    <div class="col-sm-8">
                        <label class="radio-inline text-danger">
                            <input type="radio" name="wsarticle_home" value="0" checked> 取消首页
                        </label>
                        <label class="radio-inline text-success">
                            <input type="radio" name="wsarticle_home" value="1"> 首页显示
                        </label>
                        <label class="radio-inline text-danger">
                            <input type="radio" name="wsarticle_recommend" value="0" checked> 取消推荐
                        </label>
                        <label class="radio-inline text-success">
                            <input type="radio" name="wsarticle_recommend" value="1"> 推荐内容
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 col-sm-2" for="wsarticle_create_time">时间</label>
                    <div class="col-md-2">
                        <input type="text" name="wsarticle_create_time" value="{:date('Y-m-d H:i:s')}" class="form-control" placeholder="时间">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 col-sm-2" for="wsarticle_views">浏览量</label>
                    <div class="col-md-4">
                        <input type="number" name="wsarticle_views" value="0" class="form-control" placeholder="浏览量">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 col-sm-2" for="wsarticle_source">来源</label>
                    <div class="col-md-4">
                        <input type="text" name="wsarticle_source" value="" class="form-control" placeholder="来源">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 col-sm-2" for="wsarticle_author">作者</label>
                    <div class="col-md-4">
                        <input type="text" name="wsarticle_author" value="" class="form-control" placeholder="作者">
                    </div>
                </div>
            </fieldset>
            <hr class="mt0">
            <div class="text-center">
                <button type="submit" class="btn btn-primary btn-submit">保存信息</button>
            </div>
        </div>
    </div>
</form>
{/block}


<!-- JS -->
{block name="js"}
    {load href="/static/lib/jquery/jquery.form.js"}
    {load href="/static/lib/jquery/jquery.tmpl.min.js"}
    {load href="/static/lib/jquery/jquery.ztree.all.min.js"}
    {load href="/static/lib/validator/validator.min.js"}
    {load href="/static/lib/simpleupload/simpleUpload.min.js"}
    {load href="/static/lib/sortable/zui.sortable.min.js"}
    {load href="/static/ueditor/ueditor.config.js"}
    {load href="/static/ueditor/ueditor.all.min.js"}
    {load href="/static/ueditor/lang/zh-cn/zh-cn.js"}
{/block}
{block name="jscode"}
<script id="image_tpl" type="text/html"> 
    <div class="col-sm-3 col-xs-6 upload-list-item">
        <div class="card">
            <div class="media-wrapper">
                <img class="img-bg img-5x3" style="background-image:url(${file_path})">
            </div>
            <div class="card-input">
                <input type="text" class="form-control" name="wsarticle_image[${file_id}][file_name]" value="${file_name}">
            </div>
            <div class="card-content">
                <span class="pull-right">大小：<b>${file_size}</b></span>后缀：<b>${file_ext}</b>
            </div>
            <a class="card-delete" data-file-path="${file_path}"><i class="icon icon-trash"></i></a>
        </div>
        <input type="hidden" name="wsarticle_image[${file_id}][file_path]" value="${file_path}">
        <input type="hidden" name="wsarticle_image[${file_id}][file_ext]" value="${file_ext}">
        <input type="hidden" name="wsarticle_image[${file_id}][file_size]" value="${file_size}">
    </div>
</script>
{if($column['column_cate'])}
<script id="cate_tpl" type="text/html">
    <div class="form-group">
        <label class="col-md-2 col-sm-2" for="wsarticle_cateid">&nbsp;</label>
        <div class="col-sm-3">
            <select class="form-control" name="wsarticle_cateid[]">
                {volist name="wscate" id="vo"}
                <option value="{$vo['wscate_id']}">{:dp_prefix($vo['wscate_path'])} {$vo['wscate_name']}</option>
                {/volist}
            </select>
        </div>
        <div class="col-sm-2"><button type="button" class="btn btn-danger" onClick="btn_del_cate($(this))"><i class="icon icon-minus"></i> 删除分类</button></div>
        <div class="col-sm-2 help-block with-errors"></div>
    </div>
</script>
{/if}
<script type="text/javascript">
$(document).ready(function() {
    // tinymce 编辑器
    // tinymce.init(tinymce_default_options);
    var ue = UE.getEditor('wsarticle_details');
    var ueditor = $(".ueditor");
    ueditor.each(function(params) {
        UE.getEditor($(this).attr('id'));
    })

    // 文件上传
    var file_id = 0;
    $("#upload-list .btn-upload-file").click(function(event) {
        var uploadList = $("#upload-list>.panel-body");
        var settings = { uploadUrl: "{:url('@admin/upload/image')}", multiple: true, limit: 10 };
        // 文件开始上传
        var startFunc = function(file) {sxj.loading();}
        // 文件上传成功后的回调函数
        var successFunc = function(response) {
            var data = response.data;
            if (response.code == 1) {
                file_id = file_id + 1;
                data.file_id = file_id;
                sxj.msg_success(data['file_name'] + ' 上传成功');
                $("#image_tpl").tmpl(data).appendTo(uploadList);
            } else {
                sxj.msg_error(response.msg);
            }
        }
        // 调用上传插件
        sxj.upload(settings, successFunc, startFunc);
    });

    // 上传文件排序
    $('#upload-list').sortable({selector: '.upload-list-item'})
    $('#upload-list').on('click', '.form-control', function(e){
        sxj.stop_event(e);
    }).on('mousedown', '.form-control', function(e) {
        sxj.stop_event(e);
    }).on('click', '.card-delete', function(e) {
        // 删除文件
        var file_path = $(this).data('file-path');
        var card_item = $(this).parents('.upload-list-item');
        var url = "{:url('@admin/upload/delete')}?file_path="+file_path;
        // 删除文件 删除html
        sxj.upload_list_delete(url, card_item);
        sxj.stop_event(e);
        return false;
    });

    // 自定义字段 图片上传 文件上传
    var settings_image = {
        uploadUrl: "{:url('@admin/upload/image')}",
        accept: "image/*",
        allowedExts: ["jpg", "jpeg", "png", "gif"], // 允许上传后缀
        allowedTypes: ["image/pjpeg", "image/jpeg", "image/png", "image/x-png", "image/gif", "image/x-gif"],
    };

    var settings_file = {
        uploadUrl: "{:url('@admin/upload/file')}",
        accept: "text/plain,application/zip,application/gzip,application/pdf",
        allowedExts: ["txt", "zip", "gzip", "pdf"],
        allowedTypes: ["text/plain", "application/zip", "application/x-zip", "application/gzip", "application/x-zip-compressed", "application/pdf"],
    };

    // 上传文件
    $("[data-param-upload]").click(function(event) {
        var param_type = $(this).data('param-type');
        var input_name = $(this).data('input-name');

        if ($("input[name=" + input_name + "]").val() != '') {
            if (param_type == 'image') {
                return sxj.msg_error('提示：请先删除图片!');
            }
            if (param_type == 'file') {
                return sxj.msg_error('提示：请先删除附件!');
            }
        }
        
        // 配置文件
        var settings = param_type == 'file' ? settings_file : settings_image;
        // 开始上传
        var startFunc = function(file) {sxj.loading();}
        // 上传成功
        var successFunc = function(response) {
            sxj.msg_success('文件上传成功');
            var data = response.data;
            $("input[name=" + input_name + "]").val(data.file_path)
        }

        // 调用上传插件
        sxj.upload(settings, successFunc, startFunc);
    });

    // 预览 下载
    $("[data-param-preview],[data-param-download]").click(function(event) {
        var input_name = $(this).data('input-name');
        var file_path = $("input[name="+input_name+"]").val();
        if(file_path == ''){
            return sxj.msg_error('提示：文件不存在');
        }
        window.open(file_path);
    });

    // 删除文件
    $("[data-param-delete]").click(function(event) {
        var input_name = $(this).data('input-name');
        var file_path = $("input[name='" + input_name + "']").val();
        if(file_path == ''){
            return sxj.msg_error('提示：文件不存在');
        }
        var url = "{:url('@admin/upload/delete')}?file_path=" + file_path;
        sxj.upload_delete(url, input_name);
    });

    // 添加分类
    $("#btn_add_cate").click(function() {
        $("#cate_tpl").tmpl().appendTo("#expand_cate_list");
    });

    // 删除分类
    btn_del_cate  = function(that) {
        that.parents('div.form-group').remove();
    }
});
</script>
{/block}